﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Jumpton.SFA.Server.BusinessRule.MasterData;
using Jumpton.SFA.Server.Entity;

public partial class masterdata_WareHouse_From_Products_Detail : PageBase
{
    WareHouseFromProductManager manager = new WareHouseFromProductManager();
    private int _ID =0;
    private int _ProductID = 0;
    private string _ProductName = "";
    private string _ShipFromCode = "";

    protected void Page_Load(object sender, EventArgs e)
    {
        if (null == Request["productid"])
        {
            _ProductID = 0;
        }
        else
        {
            _ProductID = Convert.ToInt32(Request["productid"]); ;
        }
        if (null == Request["code"])
        {
            _ID = 0;
        }
        else
        {
            _ID = Convert.ToInt32(Request["code"]); ;
        }
        _ProductName = Request.QueryString["productname"];
        _ShipFromCode = Request.QueryString["ShipFrom"];

        txtCode.Value = _ProductID.ToString();
        txtName.Value = _ProductName;

        if (!IsPostBack)
        {
            GetUomsType();
            PRODUCT_SHIP_FROM productfrom = manager.Load(_ID);

            if (productfrom!=null)
            {
                txtCSPrice.Value = productfrom.CASEPRICE.ToString();

                txtNumber.Value = productfrom.DISPLAYSEQUENCE.ToString();
                txtPC.Value = productfrom.INVENTORY.ToString();
                txtWithIncode.Value = productfrom.INTERNALPRCODE;
                txtPirce.Value = productfrom.PIECEPRICE.ToString();
                ddlUoms.SelectedValue = productfrom.UOMCODE;
                chkYesNo.Checked = productfrom.ACTIVE;
            }
        }
    }

    #region 绑定基本规格
    public void GetUomsType()
    {
        //ddlUoms.DataSource = UomsManager.GetUoms(MyStateManager.DomainID);
        //ddlUoms.DataTextField = "UomsDescription";
        //ddlUoms.DataValueField = "UomsCode";
        //ddlUoms.DataBind();
        //ddlUoms.Items.Insert(0, new ListItem("-选择规格-", ""));
    }
    #endregion

    protected void btnSave_Click(object sender, EventArgs e)
    {
        PRODUCT_SHIP_FROM productfrom = null;

        productfrom = manager.Load(_ID);
        if (productfrom == null)
            productfrom = new PRODUCT_SHIP_FROM();

        productfrom.ProductID = Int32.Parse(txtCode.Value);
        productfrom.PIECEPRICE =Decimal.Parse(txtPirce.Value);
        productfrom.UOMCODE = ddlUoms.SelectedValue;
        productfrom.SHIPFROMCODE = _ShipFromCode;
        productfrom.INTERNALPRCODE = txtWithIncode.Value;
        productfrom.DISPLAYSEQUENCE = Decimal.Parse(txtNumber.Value);
        productfrom.INVENTORY = Decimal.Parse(txtPC.Value);
        productfrom.CASEPRICE = Decimal.Parse(txtCSPrice.Value);
        productfrom.ACTIVE = chkYesNo.Checked;
        productfrom.DOMAINID = MyStateManager.DomainID;
        productfrom.LAST_UPDATER = MyStateManager.Name;//取到当前登陆用户名
        productfrom.LAST_UPDATE_TIME = Jumpton.SFA.Server.BusinessRule.BusinessLogic.GetDateTimeDecimal(DateTime.Now);

        manager.Save(productfrom);

        Response.Redirect("WareHouse_From_Products_List.aspx");
        
    }
    protected void btnBack_Click(object sender, EventArgs e)
    {
        Response.Redirect("WareHouse_From_Products_List.aspx");
    }
}
